package org.cu.ooad.finalproject.layar;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import com.google.appengine.repackaged.org.json.JSONArray;
import com.google.appengine.repackaged.org.json.JSONException;
import com.google.appengine.repackaged.org.json.JSONObject;

public class POI {
	
	private final static Logger log = Logger.getLogger(POI.class.getName());
	
	private ImageSearchBehavior imageSearchBehavior;

	private double lat;
	private double lon;

	private String title;
	private String attribution;
	private String line2;
	private String line3;
	private String line4;
	private String imageURL;

	private boolean showSmallBiw;
	private boolean showBiwOnClick;

	private List<Action> actions;

	public POI(String title, double lat, double lon) {
		this.title = title;
		this.lat = lat;
		this.lon = lon;
		this.actions = new ArrayList<Action>();
		actions.add(new Action("http://www.colorado.edu/parking/parking/",
				"Campus Parking"));
		actions.add(new Action("http://www.colorado.edu/events/","Campus Events"));
		attribution = "University of Colorado at Boulder";
		line2 = "";
		line3 = "";
		line4 = "";
		showSmallBiw = true;
		showBiwOnClick = true;
		
		imageSearchBehavior = new DefaultImageSearch();
		imageURL = imageSearchBehavior.getImageURL("");
	}
	
	public JSONObject getJSON() {
		JSONObject obj = new JSONObject();
		try {
			obj.put("id", getID());
			obj.put("title", title);
			obj.put("type", 1);
			obj.put("lat", (int)Math.round(lat*1000000));
			obj.put("lon", (int)Math.round(lon*1000000));
			JSONArray actions = new JSONArray();
			for (int i=0; i<this.actions.size(); i++) {
				actions.put(this.actions.get(i).getJSON());
			}
			obj.put("actions", actions);
//			obj.put("actions", new JSONArray());
			obj.put("attribution", attribution);
			obj.put("line2", line2);
			obj.put("line3", line3);
			obj.put("line4", line4);
			obj.put("imageURL", imageURL);
			obj.put("showSmallBiw", showSmallBiw);
			obj.put("showBiwOnClick", showBiwOnClick);
			
		} catch (JSONException e) {
			log.warning("Error while creating JSON: "+e.getMessage());
		}
		return obj;
	}

	public POI() {
		this("", 0, 0);
	}
	
	public double getDistance() {
		return 0;
	}
	
	public String getID() {
		return Double.toString(lat*lon);
	}
	
	public double getLat() {
		return lat;
	}

	public void setLat(double lat) {
		this.lat = lat;
	}

	public double getLon() {
		return lon;
	}

	public void setLon(double lon) {
		this.lon = lon;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getAttribution() {
		return attribution;
	}

	public void setAttribution(String attribution) {
		this.attribution = attribution;
	}

	public String getLine2() {
		return line2;
	}

	public void setLine2(String line2) {
		this.line2 = line2;
	}

	public String getLine3() {
		return line3;
	}

	public void setLine3(String line3) {
		this.line3 = line3;
	}

	public String getLine4() {
		return line4;
	}

	public void setLine4(String line4) {
		this.line4 = line4;
	}

	public String getImageURL() {
		return imageURL;
	}

	public void setImageURL(String imageURL) {
		this.imageURL = imageURL;
	}

	public boolean isShowSmallBiw() {
		return showSmallBiw;
	}

	public void setShowSmallBiw(boolean showSmallBiw) {
		this.showSmallBiw = showSmallBiw;
	}

	public boolean isShowBiwOnClick() {
		return showBiwOnClick;
	}

	public void setShowBiwOnClick(boolean showBiwOnClick) {
		this.showBiwOnClick = showBiwOnClick;
	}

	public List<Action> getActions() {
		return actions;
	}

	public void setActions(List<Action> actions) {
		this.actions = actions;
	}
	
	public ImageSearchBehavior getImageSearchBehavior() {
		return imageSearchBehavior;
	}

	public void setImageSearchBehavior(ImageSearchBehavior imageSearchBehavior) {
		this.imageSearchBehavior = imageSearchBehavior;
	}

}
